﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.Record;


namespace TyMES.ViewModel.Record.MaterialPDVMs
{
    public partial class MaterialPDListVM : BasePagedListVM<MaterialPD_View, MaterialPDSearcher>
    {

        protected override IEnumerable<IGridColumn<MaterialPD_View>> InitGridHeader()
        {
            return new List<GridColumn<MaterialPD_View>>{
                this.MakeGridHeader(x => x.LineCode),
                this.MakeGridHeader(x => x.OperationCode),
                this.MakeGridHeader(x => x.OperationName),
                this.MakeGridHeader(x => x.CurrentSN),
                this.MakeGridHeader(x => x.AnotherSN),
                this.MakeGridHeader(x => x.PDname),
                this.MakeGridHeader(x => x.PDcode),
                this.MakeGridHeader(x => x.result),
                this.MakeGridHeader(x => x.PDdata),
                this.MakeGridHeader(x => x.orderCode),
                this.MakeGridHeader(x => x.schduleCode),
                this.MakeGridHeader(x => x.uploadTime),
                this.MakeGridHeader(x => x.uploadFlag),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<MaterialPD_View> GetSearchQuery()
        {
            var query = DC.Set<MaterialPD>()
                .CheckContain(Searcher.OperationCode, x=>x.OperationCode)
                .CheckContain(Searcher.CurrentSN, x=>x.CurrentSN)
                .CheckContain(Searcher.AnotherSN, x=>x.AnotherSN)
                .CheckContain(Searcher.PDcode, x=>x.PDcode)
                .CheckContain(Searcher.result, x=>x.result)
                .CheckContain(Searcher.orderCode, x=>x.orderCode)
                .CheckContain(Searcher.schduleCode, x=>x.schduleCode)
                .Select(x => new MaterialPD_View
                {
				    ID = x.ID,
                    LineCode = x.LineCode,
                    OperationCode = x.OperationCode,
                    OperationName = x.OperationName,
                    CurrentSN = x.CurrentSN,
                    AnotherSN = x.AnotherSN,
                    PDname = x.PDname,
                    PDcode = x.PDcode,
                    result = x.result,
                    PDdata = x.PDdata,
                    orderCode = x.orderCode,
                    schduleCode = x.schduleCode,
                    uploadTime = x.uploadTime,
                    uploadFlag = x.uploadFlag,
                })
                .OrderByDescending(x => x.ID);
            return query;
        }

    }

    public class MaterialPD_View : MaterialPD{

    }
}
